home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48hor2 / chkrx.s < prev    next >
Text File  |  1994-01-04  |  8KB  |  226 lines

  1. ******************************************************************
  2. ** CHKRX  
  3. **
  4. ** -Sample program that checks RX pin of serial port
  5. **  I show all the UART status bits on these annunciators:
  6. **
  7. **  LowBat      bRX     ( rx pin high, i hope )
  8. **  RightShift  bRBZ    ( receiver busy )
  9. **  LeftShift   bRBF    ( receive buffer full )
  10. **  Alpha       bRER    ( receive error??? )
  11. **  IO                  ( last 0 was a one->zero transition )
  12. **
  13. ** - press ON (ATTN) to exit
  14. ** 
  15. **  INPUT:   none
  16. **
  17. **  OUTPUT:  1: zeroes%     ( number of zeroes on RX )
  18. **      - this number refers to how many one->zero transitions occurred
  19. **
  20. **
  21. ** COMMENTS:  try typing quickly to watch the error (alpha) come on
  22. **            is you run this with normal serial IO, the RX 
  23. **            annunciator ((*)) never seems to go off. i don't
  24. **            know much about serial IO, but that tells me that
  25. **            RX=1 is an idle condition
  26. **
  27. ** 10/9/92 - Robert Sanders
  28. **           any questions, comments, etc. e-mail to
  29. **   pshuprs@prism.gatech.edu      or   gt8134b@prism.gatech.edu
  30. ******************************************************************
  31.  
  32. ASSEMBLE
  33.     NIBASC \HPHP48-E\
  34.  
  35. ** misc UART addresses
  36. CRER    EQU     #113    ( write here to clear RER )
  37. RBF     EQU     #114    ( 2-nibble, receive buffer )
  38.  
  39. ** STATUS SERVICE DELAY CONSTANTS
  40. **
  41. ** these allow the RER and RBF annunciators and status bits to
  42. ** stay set for a while, then be cleared.  the numbers are
  43. ** #'s of iterations before clearing, and the translation of
  44. ** loops->clock cycles->milliseconds will vary slightly with
  45. ** your HP48, and also with which bits get set 
  46. **
  47. ** there is no hardware reason to do this, but you need this
  48. ** to see any results.
  49. ** the side effect is, a character received isn't taken out of
  50. ** the receive buffer for 600 loop iterations (it can easily
  51. ** choke at 9600 baud.)
  52.  
  53. RERCOUNT EQU 600
  54. RBFCOUNT EQU 600        
  55.  
  56. **  UART status bits (at addr #111)
  57. bRBF    EQU     0       ( receive buffer full   )
  58. bRBZ    EQU     1       ( receiver busy         )
  59. bRER    EQU     2       ( receive error?        )
  60. bRX     EQU     3       ( rx pin high????       )
  61.  
  62. ** UART control bits
  63. bERBZ   EQU     0       ( enable interrupt for RBZ?  )
  64. bERBF   EQU     1       ( enable interrupt for RBF?  )
  65. bETBE   EQU     2       ( I'd say TransmitBufferEmpty, but dunno )
  66. bSON    EQU     3       ( enable UART I/O - SerialON )
  67.  
  68. ** ST bits used
  69. sRER    EQU     0
  70. sRBF    EQU     1
  71. RPL
  72.  
  73. *============================================================*
  74. *                 RPL STARTS HERE                            *
  75. *============================================================*
  76. ::
  77.    CLEARVDISP
  78.    $ "ALARM ------ RX"          DISPROW1
  79.    $ "LS: RBF    RS: RBZ"       DISPROW3
  80.    $ "A:  RER"                  DISPROW4 
  81.  
  82.    CODE
  83.         gosbvl  =SAVPTR         * save regs
  84.         d0=(5)  =DISABLE_KBD
  85.         la(1)   #F
  86.         dat0=a  1               * disable keyboard polling (flag)
  87.         INTOFF                  * shut off keyboard interrupts
  88.  
  89.         la(2)   #80
  90.         d0=(5)  =ATTNFLG
  91.         dat0=a  1               * init to 0 ON key presses
  92.  
  93. ************************************************************
  94. ***********************  ROM INFO  *************************
  95. ************************************************************
  96. * here's what OpenUartClr at #3161e (PMC) does to setup
  97. * it sets ERBF (enable receive buffer full interrupt?)
  98. *         ERBZ (enable receiver busy interrupt?)
  99. *         SON  (SerialON - enable UART I/O)
  100. *
  101. *       d1=(5)  #110
  102. *       lc(1)   #b              * sets SON, ERBF, ERBZ 
  103. *       dat1=c  4
  104. ************************************************************
  105.  
  106. * the following is iffy
  107.         d1=(5)  =IOC            * IOControl register (UART control) 
  108.         lc(1)   2^bSON          * set bSON bit
  109.         dat1=c  1
  110.  
  111.         d1=d1+  1               * serial receive control/status at #111h
  112.  
  113.         d0=(5)  =ANNCTRL        * annunciator contol (bit 2=ALPHA)
  114.         dat0=a  2               * turn all annunciators off, but leave
  115.                                 * enabled (a should be 80 here)
  116.  
  117.         st=0    sRER            * no RER condition yet
  118.         st=0    sRBF            * no RBF condition yet
  119.  
  120.         lc(5)   0
  121.         r0=c    a
  122.         
  123. ** in this loop, D1 points to the RX status mibb6e
  124. **               D0 points to the annunciator control nibble upon
  125. **                  entry (and loop), but changes
  126. **               R0 counts zeroes on RX
  127. **               ST<0> indicates RER condition unserviced
  128. **               ST<1> indicates RBF condition unserviced
  129. **                B holds counter for clearing RER. at b=0, clears
  130. **                D holds counter for clearing RBF. at b=0, clears
  131. **
  132.  
  133. mloop   c=dat1  1               * get RX status nibble
  134.         ?cbit=1 bRX
  135.         goyes   postzero        * after zero processing
  136.  
  137. ** this code does "zero processing"
  138. **   if RX=0 last time, the IO annunciator is cleared
  139. **   if RX=1 last time, the IO annunciator is set and the zero counter
  140. **                      is incremented. this flags a one->zero transition
  141. **
  142. ** the zero counter is kept in R0
  143. **
  144.         a=dat0  1               * get old annunciators
  145.         ?abit=1 bRX             * RX ann was set, so transition occurred
  146.         goyes   trans   
  147. notrans                         * comes here if RX is zero,
  148.                                 * but RX was zero before
  149.         d0=d0+  1               * point to ANN2
  150.         la(1)   8               * ANN_ON=8, IO_ANN=2
  151.         dat0=a  1
  152.         d0=d0-  1               * point back to ANNCTRL (ANN1)
  153.         goto    postzero
  154.  
  155. trans
  156.         d0=d0+  1               * point to ANN2
  157.         la(1)   10              * ANN_ON=8, IO_ANN=2
  158.         dat0=a  1
  159.         d0=d0-  1               * point back to ANNCTRL (ANN1)
  160.         a=r0    a               * increment 0 counter
  161.         a=a+1   a               * ..
  162.         r0=a    a               * ..
  163.  
  164. ** post "zero processing"
  165. postzero                        
  166.         dat0=c  1               * drive RX status onto annun.
  167.  
  168.         ?cbit#1 bRER            * if no RER condition, check RBF
  169.         goyes   chkrbf
  170.  
  171. *************** service RER **************
  172. chkrer  ?st=1   sRER
  173.         goyes   cntrer
  174.         st=1    sRER            * flag the new RER
  175.         la(5)   RERCOUNT        * times to countdown before clearing
  176.         b=a     a
  177.         goto    chkrbf
  178. cntrer  b=b-1   a               * service old RER
  179.         ?b#0    a
  180.         goyes   chkrbf          * not displayed long enough yet
  181.         d0=(5)  CRER            * address to clear RER
  182.         dat0=a  1               * any value will clear
  183.         st=0    sRER            * mark old RER condition gone
  184.  
  185. *************** service RBF **************
  186. chkrbf  ?cbit#1 bRBF            * no RBF condition
  187.         goyes   chkattn 
  188.         ?st=1   sRBF
  189.         goyes   cntrbf
  190.         st=1    sRBF            * flag the new RBF
  191.         lc(5)   RBFCOUNT        * times to countdown before clearing
  192.         d=c     a
  193.         goto    chkattn
  194. cntrbf  d=d-1   a               * service old RBF
  195.         ?d#0    a
  196.         goyes   chkattn         * not displayed long enough yet
  197.         d0=(5)  RBF             * address of receive buffer
  198.         a=dat0  2               * get buffered byte
  199.         st=0    sRBF            * mark old RBF condition gone
  200.  
  201. chkattn
  202.         d0=(5)  =ATTNFLG
  203.         c=dat0  1               * get annctrl nibble
  204.         ?c#0    p               * ON pressed yet?
  205.         goyes   done            * exit program
  206.         d0=(5)  =ANNCTRL
  207.         goto    mloop
  208.  
  209. ** get us back to the normal system state
  210. done    d0=(5)  =DISABLE_KBD
  211.         la(1)   0
  212.         dat0=a  1               * enable keyboard polling
  213.         INTON
  214.         d1=(5)  =IOC            * IOControl register (UART control) 
  215.         lc(1)   0               * clear all, especially bSON 
  216.         dat1=c  1               * (turn serial I/O off)
  217.  
  218.         gosbvl  =GETPTR         * restore RPL registers
  219.         govlng  =PUSH#LOOP      * pushes R0 as sysbin and reenter
  220.                                 * RPL main loop
  221.    ENDCODE
  222.  
  223.  
  224.    UNCOERCE                     ( turn # into real )
  225. ;
  226.